﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using QXBook.Model;
using QXBook.Utils;
using QXBook.Service;
using QXBook.Controls.HtmlControls;
using Web.App_Code;

namespace Web.Product
{
    public partial class Product_List : UserBasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.TextBind(null);
            }
        }

        private void TextBind(ProductCondition condition)
        {
            PagerState ps = new PagerState();
            if (string.IsNullOrEmpty(CommonUtils.Get("page")))
            {
                ps.CurrentPage = 1;
            }
            else
            {
                ps.CurrentPage = CommonUtils.ToInt(CommonUtils.Get("page"));
            }
            ps.PageSize = 9;

            List<ProductInfo> list = ServiceFactory.CreateInstance<ProductService>().GetModelList(ref ps, condition);

            this.rptList.DataSource = list;
            this.rptList.DataBind();

            divPage.Text = ClientPager.CreatePager(ps);
        }

        protected void rptList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            ProductInfo product = (ProductInfo)e.Item.DataItem;
            //Span sId = (Span)e.Item.FindControl("sId");
            Anchor aImg = (Anchor)e.Item.FindControl("aImg");
            //Anchor aTitle = (Anchor)e.Item.FindControl("aTitle");
            Span sPrice = (Span)e.Item.FindControl("sPrice");

            aImg.Text = "<img src='" + product.ListImg + "' width='105' height='155' class='img' />";
            aImg.Href = "Product_View.aspx?ProductID=" + product.ProductID.ToString();
            //sId.Text = product.ProductID.ToString();
            //aTitle.Text = product.Title;
            //aTitle.Href = "Product_View.aspx?ProductID=" + product.ProductID.ToString();
            sPrice.Text = "￥" + product.Price;
        }
    }
}